package org.archive.crawler.frontier;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.archive.crawler.datamodel.CandidateURI;
import org.archive.crawler.extractor.Link;
import org.archive.crawler.postprocessor.FrontierScheduler;
import org.archive.io.ReplayCharSequence;
import org.archive.util.HttpRecorder;


public class MyFrontierScheduler extends FrontierScheduler{

	/**
	 * 
	 */
	public static final String pattern_ahref = "<a\\s+href\\s*=\\s*(\"([^\"]*)\"|[^\\s>])\\s*>";
	public static final String jd = "http://news.sohu.com/[\\d]+/n[\\d]+.shtml";

	public MyFrontierScheduler(String name) {
		super(name);
		// TODO Auto-generated constructor stub
	}
	
	protected void schedule(CandidateURI curi){
		

		String url=curi.toString();
//		ReplayCharSequence cs=null;
//		try
//		{
//			HttpRecorder hr=curi.getHttpRecorder();
//			cs=hr.getReplayCharSequence();
//		}catch(Exception ex)
//		{
//			ex.printStackTrace();
//		}
//		if(cs==null)
//			return;
//		String content=cs.toString();
//		
//		try{
//			Pattern pattern=Pattern.compile(pattern_ahref, Pattern.CASE_INSENSITIVE);
//			Matcher matcher=pattern.matcher(content);
//			
//			while(matcher.find())
//			{
//				String newUrl=matcher.group(2);
//				if(newUrl.matches(jd))
//				{
//					this.getController().getFrontier().schedule(curi);
//				}
//			}
//		}catch(Exception ex)
//		{
//			ex.printStackTrace();
//		}
		
		
		
//		if (url.endsWith(".zip") || url.endsWith(".rar") || url.endsWith(".exe") || url.endsWith(".pdf")  || url.endsWith(".doc") 
//			|| url.endsWith(".xls") || url.endsWith(".css") ||url.endsWith(".js"))
//		{  
//			return;  
//		} 
		
		
//		if(url.equals("dns:www.gilt.com"))
//			this.getController().getFrontier().schedule(curi);
//		
//		System.out.println("MyFrontierScheduler֮ǰ :"+url);
//		
//		String reg="http://www.gilt.com/sale/women/(.*?)";
//		String reg1="http://www.gilt.com/sale/women/(.*?)[.](.*?)";
//		
//		Matcher mat1 = Pattern.compile(reg1).matcher(curi.toString());
//		if(mat1.find())
//			return;
//		
//		Matcher mat = Pattern.compile(reg).matcher(curi.toString());
//		if(mat.find())
//		{
//			System.out.println("MyFrontierScheduler    :"+url);
//			this.getController().getFrontier().schedule(curi);
//		}
		
		
		
		if(url.equals("dns:shop.nordstrom.com"))
		this.getController().getFrontier().schedule(curi);
	
	System.out.println("MyFrontierScheduler֮ǰ :"+url);
	
	String reg="http://shop.nordstrom.com/c/all-baby-kids/";

	
	Matcher mat = Pattern.compile(reg).matcher(curi.toString());


	String reg1="http://shop.nordstrom.com/c/all-baby-kids/(.*?)";

	
	Matcher mat1 = Pattern.compile(reg1).matcher(curi.toString());
	if(mat1.find())
	{
		System.out.println("MyFrontierScheduler    :"+url);
		this.getController().getFrontier().schedule(curi);
	}
	
	
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
